<template>
   <v-btn :btnConfig="btnConfig" @upFile="importFile" @exportJd="exportJd" @exportTh="exportTh"></v-btn>
</template>

<script>
import btn from "@/components/commons/TableTitle";

export default {
   name: "",
   props: {},
   data() {
      return {
         btnConfig: [
            {label: this.$t('out.exportJd'), invalid: "exportJd"},
            {label: this.$t('out.exportTh'), invalid: "exportTh"},
            {type: "file1", label: this.$t('common.import'), invalid: "importFile"},
         ],
      }
   },
   methods: {
      async exportJd() {
         var downloadElement = document.createElement("a");
         var href = ""; //创建下载的链接
         downloadElement.style.display = "none";
         downloadElement.href = href;
         downloadElement.download = ""; //下载后文件名
         document.body.appendChild(downloadElement);
         downloadElement.click(); //点击下载
         document.body.removeChild(downloadElement); //下载完成移除元素
      },
      exportTh() {
         var downloadElement = document.createElement("a");
         var href = ""; //创建下载的链接
         downloadElement.style.display = "none";
         downloadElement.href = href;
         downloadElement.download = ""; //下载后文件名
         document.body.appendChild(downloadElement);
         downloadElement.click(); //点击下载
         document.body.removeChild(downloadElement); //下载完成移除元素
      },
      async importFile(data) {
         try {
            let res = await this.$api.post(`/AllImportsExcelServlet`, {data: data});
            let data = JSON.parse(res.data);
            if (data.type === "error") {
               this.$message.error(data.msg);
            } else {
               this.$message.success(data.msg);
               this.$parent.$refs.table.tableData = data.errorDetail;
            }
         } catch (e) {
            this.$message.error(this.$t('app.err'));
         }
      },
   },
   components: {
      "v-btn": btn
   }
}
</script>

<style scoped>

</style>
